1. /* sdfdrand.cpp by K.Tsuru */
  2. // function ID 3005 DRADIX, BRADIX
  3. /********************************************************
  4. SDouble class for test
  5. Provides a random number with radix=rdx and exponent=exp.
  6. Default value exp = 0, radix = DRADIX.
  7. If size == 0 or size is greater than maxmum size it is
  8. adujusted to the maximum size.
  9. ******************************************************/
  10. #ifndef SN_H
  11. #include "sn.h"
  12. #endif
  13. #include <time.h>
  14. SDouble DRand(uint size, int exp, fType radix){
  15. SNumber::NumberType tp = (radix > DRADIX) ? SNumber::BIN_DEC : SNumber::REAL;
  16. fType rdx = (radix > DRADIX) ? BRADIX : DRADIX;
  17. uint max_sz = SNManager::SNMaxSize(tp);
  18. if(!size || (size > max_sz) ) size = max_sz;
  19. SDouble result(tp, size); // result = 0
  20. FigBlock a(size);
  21. time_t t;
  22. static uint seed = (uint)time(&t);
  23. srand(seed);
  24. uint j, first = (tp == SNumber::REAL) ? 1 : 0;
  25. if(first) a[0] = 0;
  26. for(j = first; j < size ; j++) a[j] = (fType)(rand() % rdx);
  27. fType f1 = first ? DRADIX/10 : BRADIX/8;
  28. while(a[first] < f1) a[first] = (fType)(rand() % rdx); //donot give 0.0001 1234.....
  29. seed = (uint)rand(); // set new seed for next call.
  30. result.SetFigBlock(a, result.PLUS, exp); // result.CheckArray(); done
  31. return result;
  32. }

sdfdrand.cpp : last modifiled at 2017/03/13 14:31:58(1,272 bytes)
created at 2017/10/07 10:22:50
The creation time of this html file is 2017/10/07 11:29:39 (Sat Oct 07 11:29:39 2017).